//
//  YXPartnerAleatView.m
//  CreditCard
//
//  Created by 杨旭 on 2017/12/28.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "YXPartnerAleatView.h"

@interface YXPartnerAleatView ()

@property (weak, nonatomic) IBOutlet UIView *alertView;

@property (weak, nonatomic) IBOutlet UIImageView *picImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *pidCodeLab;
@property (weak, nonatomic) IBOutlet UILabel *numberLab;


@end
@implementation YXPartnerAleatView

- (void)setModel:(YXUserInfoModel *)model {
    _model = model;
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:_model.imgUrl] placeholderImage:[UIImage imageNamed:@""]];
    _nameLab.text = _model.name;
    _pidCodeLab.text = [NSString stringWithFormat:@"推荐码：%@",_model.pid];
    _numberLab.text = [NSString stringWithFormat:@"合伙人数：%@人",_model.nextAgentCounts];
}


-(instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        NSArray *viewArray = [[NSBundle mainBundle]loadNibNamed:@"YXPartnerAleatView" owner:self options:nil];
        self = viewArray[0];
        self.frame = frame;
        [self setup];
    }
    return self;
    
}

- (void)setup {
    self.picImageView.layer.masksToBounds = YES;
    self.picImageView.layer.cornerRadius = self.picImageView.W / 2;
    self.alertView.layer.masksToBounds = YES;
    self.alertView.layer.cornerRadius = 10.0f;
    
}

- (IBAction)reportBtnAction:(UIButton *)sender {
    [self removeFromSuperview];
    if (self.clickReportBtnBlock) {
        self.clickReportBtnBlock();
    }
}

- (IBAction)closeBtnAction:(UIButton *)sender {
    
    [self removeFromSuperview];
}


#pragma mark - 弹出 -
- (void)showCustomAlertView {
    UIWindow *rootWindow = [UIApplication sharedApplication].keyWindow;
    [rootWindow addSubview:self];
    [self creatShowAnimation];
    
}

- (void)creatShowAnimation {
    
    self.alertView.layer.position = self.center;
    self.alertView.transform = CGAffineTransformMakeScale(0.90, 0.90);
    [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:1 options:UIViewAnimationOptionCurveLinear animations:^{
        self.alertView.transform = CGAffineTransformMakeScale(1.0, 1.0);
    } completion:^(BOOL finished) {
        
    }];
    
}
@end
